package us.wili.dev.client.config;


import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(ignoreUnknownFields = false, prefix = "weixin.miniapp.config")
public class WeixinPayConfig {
    private String appId;
    private String appSecret;
    //商户号
    private String mchId;
    //支付秘钥
    private String mchKey;
    //支付通知回调地址
    private String  notifyUrl;
    //支付方式
    private String tradeType;
    //加密方式
    private String signType;


    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getAppSecret() {
        return appSecret;
    }

    public void setAppSecret(String appSecret) {
        this.appSecret = appSecret;
    }

    public String getMchId() {
        return mchId;
    }

    public void setMchId(String mchId) {
        this.mchId = mchId;
    }

    public String getMchKey() {
        return mchKey;
    }

    public void setMchKey(String mchKey) {
        this.mchKey = mchKey;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    public String getTradeType() {
        return tradeType;
    }

    public void setTradeType(String tradeType) {
        this.tradeType = tradeType;
    }

    public String getSignType() {
        return signType;
    }

    public void setSignType(String signType) {
        this.signType = signType;
    }


    /**
     * 根据插件要求封装所需bean
     * @return
     */
    @Bean
    public WxPayService wxPayService(){
        WxPayConfig config = new WxPayConfig();
        config.setAppId(this.appId);
        config.setMchId(this.mchId);
        config.setMchKey(this.mchKey);
        config.setNotifyUrl(this.notifyUrl);
        config.setTradeType(this.tradeType);
        config.setSignType(this.signType);
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(config);
        return wxPayService;
    }
}
